//
//  DepreViewController.m
//  CarHome
//
//  Created by 张世琦 on 14-9-19.
//  Copyright (c) 2014年 WJN_work@163.com. All rights reserved.
//

#import "DepreViewController.h"

@interface DepreViewController ()

@end

@implementation DepreViewController

- (void)dealloc
{
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    UIButton *leftBack = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBack setFrame:CGRectMake(0, 0, 25, 25)];
    [leftBack setImage:[UIImage imageNamed:@"BackButton.png"] forState:UIControlStateNormal];
    [leftBack addTarget:self action:@selector(leftBackMethod:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBack];
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 200, 40)];
    label.text = @"活动详情";
    label.textAlignment = NSTextAlignmentCenter;
    [label setTextColor:[UIColor whiteColor]];
    [self.navigationItem setTitleView:label];
    [label release];
}

#pragma mark -
#pragma mark 创建webview

- (void)setWebUrl:(NSString *)url
{
    _web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height - 64)];
    _web.delegate = self;
    [self.view addSubview:_web];
    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    [_web loadRequest:request];
    [_web release];
}

#pragma mark -
#pragma mark 加载背景

- (void) webViewDidStartLoad:(UIWebView *)webView
{
    //创建UIActivityIndicatorView背底半透明View
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height)];
    [view setTag:108];
    [view setBackgroundColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.1]];
    [view setAlpha:0.5];
    [self.view addSubview:view];
    
    activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectZero];
    [activityIndicator setCenter:view.center];
    [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [view addSubview:activityIndicator];
    
    [activityIndicator startAnimating];
}

#pragma mark -
#pragma mark 结束加载

- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    [activityIndicator stopAnimating];
    UIView *view = (UIView*)[self.view viewWithTag:108];
    [view removeFromSuperview];
    
    
}
- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [activityIndicator stopAnimating];
    UIView *view = (UIView*)[self.view viewWithTag:108];
    [view removeFromSuperview];
    
}
#pragma mark -
#pragma mark leftBackMethod
- (void)leftBackMethod:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
